//
//  TestViewController.m
//  Runone
//
//  Created by runone01 on 16/8/18.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "TestViewController.h"
#import "FMDBOperation.h"
#import "HighWayRoadRecord.h"
#import "TableOperation.h"
#import "AppDelegate.h"
#import "StationModel.h"
#import "DeviceBaseInfo.h"
#import "UpdateModel.h"
#import "MJExtension.h"
#import "PileInfo.h"
#import "UpdateModel.h"
#import "AllLastestVehicleDynamic.h"

@interface TestViewController ()
@property(nonatomic, strong)HighWayRoadRecord *HighWayRoadRecordModel;
@property(nonatomic, strong)NSArray *HighWayRoadRecordArray;

@property(nonatomic, strong)StationModel *StationModelModel;
@property(nonatomic, strong)NSArray *StationArray;
@property(nonatomic, strong)NSArray *deviceArray;
@property(nonatomic, strong)NSArray *PirArray;
@property(nonatomic, strong)NSArray *CarArray;
@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    AppDelegate *myDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
    self.HighWayRoadRecordArray=myDelegate.HighWayRoadArray;
    
//    AppDelegate *deviceDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
//    self.deviceArray=myDelegate.AllDeviceBaseArray;
    
    
    AppDelegate *stationDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
    self.StationArray=stationDelegate.AllTollStationArray;
    
    AppDelegate *PirDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
    self.PirArray=PirDelegate.PirArray;
    
    AppDelegate *CarDelegate = (AppDelegate*) [UIApplication sharedApplication].delegate;
    self.CarArray=CarDelegate.AllLastestVehicleDynamicArray;
    
    NSLog(@"%@",self.StationArray);
    // Do any additional setup after loading the view from its nib.
}


- (IBAction)insert:(UIButton *)sender {
    

////两客一危表
//    NSString *Insert = @"insert into CarTable(UID,CollectedRecordUID,AccessCode,TransType,MCUID,VehicleNo,Color,Cur_AccessCode ,Online_flg ,Warn_flg ,Status_flg,Latitude,Longitude ,Elevation,OD_Rate ,Locator_Rate,Mileage,Direction,DateTime_Position_Time,DateTime_RecvTime,SystemUID,SystemCode) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//    for (int i=0; i<self.CarArray.count; i++) {
//        AllLastestVehicleDynamic *Model=self.CarArray[i];
//        
//        NSString *Color=[NSString stringWithFormat:@"%ld",(long)Model.Color];
//        NSString *AccessCode=[NSString stringWithFormat:@"%ld",(long)Model.AccessCode];
//        NSString *Cur_AccessCode=[NSString stringWithFormat:@"%ld",(long)Model.Cur_AccessCode];
//        NSString *Online_flg=[NSString stringWithFormat:@"%ld",(long)Model.Online_flg];
//        NSString *Warn_flg=[NSString stringWithFormat:@"%ld",(long)Model.Warn_flg];
//        NSString *Status_flg=[NSString stringWithFormat:@"%ld",(long)Model.Status_flg];
//        NSString *OD_Rate=[NSString stringWithFormat:@"%ld",(long)Model.OD_Rate];
//        NSString *Locator_Rate=[NSString stringWithFormat:@"%ld",(long)Model.Locator_Rate];
//        NSString *Mileage=[NSString stringWithFormat:@"%ld",(long)Model.Mileage];
////        NSString *Direction=[NSString stringWithFormat:@"%ld",(long)Model.Direction];
//        NSString *Elevation=[NSString stringWithFormat:@"%ld",(long)Model.Elevation];
//        NSString *DateTime_Position_Time=[NSString stringWithFormat:@"%@",Model.DateTime_Position_Time];
//         NSString *DateTime_RecvTime=[NSString stringWithFormat:@"%@",Model.DateTime_RecvTime];
//        
//        NSArray *param=@[Model.UID,Model.CollectedRecordUID,AccessCode,Model.TransType,Model.MCUID,Model.VehicleNo,Color,Cur_AccessCode,Online_flg,Warn_flg,Status_flg,Model.Latitude,Model.Longitude,Elevation,OD_Rate,Locator_Rate,Mileage,Model.Direction,DateTime_Position_Time,DateTime_RecvTime,Model.SystemUID,Model.SystemCode];
//        
//        
//        [[TableOperation shareInstance] insertDataToTableName:Insert Data:param];
//    }

    #pragma mark ---------------------------桩号表
   // 桩号信息表
    NSString *Insert = @"insert into PirNoTable(PileUID, SystemUID,RoadUID,PileNo,Longitude,Latitude,SystemCode,RoadName,RoadType) values(?,?,?,?,?,?,?,?,?)";
        for (int i=0; i<self.PirArray.count; i++) {
            PileInfo *Model=self.PirArray[i];
    
            NSString *Longitude=[NSString stringWithFormat:@"%ld",(long)Model.Longitude];
            NSString *Latitude=[NSString stringWithFormat:@"%ld",(long)Model.Latitude];
            NSString *RoadType=[NSString stringWithFormat:@"%ld",(long)Model.RoadType];
            NSArray *param=@[Model.PileUID,Model.SystemUID,Model.RoadUID,Model.PileNo,Longitude,Latitude,Model.SystemCode,Model.RoadName,RoadType];
    
            [[TableOperation shareInstance] insertDataToTableName:Insert Data:param];
        }
    
#pragma mark ---------------------------时间表

 //时间表
//    NSString *Insert = @"insert into UpdateTimeTable(RecordUID, SystemUID,DataDescription,DataCode,DataChangeTime,SystemCode) values(?,?,?,?,?,?)";
//    
//    NSString *jsonString = @"[{\"RecordUID\":\"EE8BBF02-1D36-4C97-BE2E-13CD362927B3\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"两客一危动态数据\",\"DataCode\":\"004\",\"DataChangeTime\":\"2016-08-08 17:00:00.000\",\"SystemCode\":\"GuangleHighway\"},{\"RecordUID\":\"C15FA968-7791-4297-B269-21CF9C5B46B4\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"高速干道数据\",\"DataCode\":\"005\",\"DataChangeTime\":\"2016-08-08 17:00:00.000\",\"SystemCode\":\"GuangleHighway\"},{\"RecordUID\":\"33A81F68-7F0F-40A2-A5BF-2EDE88D4EB21\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"桩信息数据\",\"DataCode\":\"006\",\"DataChangeTime\":\"2016-08-18 19:00:00.000\",\"SystemCode\":\"GuangleHighway\"},{\"RecordUID\":\"70828A4F-59AB-40C2-AF2F-346DAF3FE5C3\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"用户权限数据\",\"DataCode\":\"003\",\"DataChangeTime\":\"2016-08-08 17:00:00.000\",\"SystemCode\":\"GuangleHighway\"},{\"RecordUID\":\"33320899-A75C-4CCD-8612-61EE56D39595\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"外场设备数据\",\"DataCode\":\"002\",\"DataChangeTime\":\"2016-08-19 17:00:00.000\",\"SystemCode\":\"GuangleHighway\"},{\"RecordUID\":\"C06953B7-1596-452C-B7ED-7C833999BAC5\", \"SystemUID\":\"4A22BBFD-428C-495C-9702-AF5FB92C3973\", \"DataDescription\":\"收费站数据\",\"DataCode\":\"001\",\"DataChangeTime\":\"2016-08-08 17:00:00.000\",\"SystemCode\":\"GuangleHighway\"}]";
//    NSArray *modelArray=[jsonString mj_JSONObject];
//    for (NSDictionary *dic in modelArray) {
//        
//        UpdateModel *model=[UpdateModel mj_objectWithKeyValues:dic];
//        
//        NSString *dataCode=[NSString stringWithFormat:@"%ld",(long)model.DataCode];
//        
//       // NSLog(@"RecordUID=%@,DataDescription=%@,DataCode=%ld,DataDescription=%@,DataChangeTime=%@,SystemCode=%@",model.RecordUID,model.DataDescription,(long)model.DataCode,model.DataDescription,model.DataChangeTime,model.SystemCode);
//        NSArray *param=@[model.RecordUID,model.DataDescription,dataCode,model.DataDescription,model.DataChangeTime,model.SystemCode];
//        
//        [[TableOperation shareInstance] insertDataToTableName:Insert Data:param];
//    }

    
//    }
#pragma mark ---------------------------设备表
//    NSString *Insert = @"insert into DeviceTable(DeviceUID, SystemUID,RoadUID,DeviceType,SerialNumber,RegionUID,Derection,PileNo,PileDistance,DeviceMode,Longitude,Latitude,DeviceSetting,SystemCode,RoadName,Distance) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
//    for (int i=0; i<self.deviceArray.count; i++) {
//        DeviceBaseInfo *Model=self.deviceArray[i];
//        
//        NSString *DeviceType=[NSString stringWithFormat:@"%ld",(long)Model.DeviceType];
//        NSString *Derection=[NSString stringWithFormat:@"%ld",(long)Model.Derection];
//        NSString *PileDistance=[NSString stringWithFormat:@"%ld",(long)Model.PileDistance];
//        NSString *Distance=[NSString stringWithFormat:@"%ld",(long)Model.Distance];
//        NSString *Longitude=[NSString stringWithFormat:@"%ld",(long)Model.Longitude];
//        NSString *Latitude=[NSString stringWithFormat:@"%ld",(long)Model.Latitude];
//        
//        NSArray *param=@[Model.DeviceUID,Model.SystemUID,Model.RoadUID,DeviceType,Model.SerialNumber,Model.RegionUID,Derection,Model.PileNo,PileDistance,Model.DeviceMode,Longitude,Latitude,Model.DeviceSetting,Model.SystemCode,Model.RoadName,Distance];
//        
//        [[TableOperation shareInstance] insertDataToTableName:Insert Data:param];
//
//    }
}
- (IBAction)update:(UIButton *)sender {
//    [[TableOperation shareInstance] UpdateTimeTable];
}



- (IBAction)query:(UIButton *)sender {
    
    
//    [[TableOperation shareInstance]  getStationTableData];
//     [[TableOperation shareInstance]  getePirNoTable];113.011436,Latitude=25.262333,RoadName=主干道,RoadType=1
         [[TableOperation shareInstance]  getePirNoTableOfRow:@"K102"];
//    [[TableOperation shareInstance]  getDeviceTable];
//    [[TableOperation shareInstance]  getUpdateTimeTable];
//    [[TableOperation shareInstance]  getHighWayRoadTable];
//   [[TableOperation shareInstance] getCarTable];
}
- (IBAction)buildTable:(UIButton *)sender {
    
    [[TableOperation shareInstance] createPirNoTable];

}
- (IBAction)delere:(UIButton *)sender {
//    [[TableOperation shareInstance] deleteTable:@"PirNoTable"];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
